#include <bits/stdc++.h>
// 2025/04/04
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

string s;
int n, dp[51][51];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    n = s.size(), s = " " + s;
    memset(dp, 0x3f, sizeof(dp));
    for (int i = 1; i <= s.size(); i++)
        dp[i][i] = 1;
    for (int len = 2; len <= n; len++)
        for (int l = 1, r = len; r <= n; l++, r++){
            if (s[l] == s[r])
                dp[l][r] = min(dp[l][r], dp[l + 1][r]);
            for (int k = l; k < r; k++)
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
        }
    cout << dp[1][n] << endl;
    return 0;
}